package com.chilly.dateapi;

import java.text.Format;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.Locale;

/**
 * Created by Chilly Cui on 2020/11/19.
 */
public class ClockDemo {
    public static void main(String[] args) {
        /*Clock clock = Clock.systemDefaultZone();
        long millis = clock.millis();
        Instant instant = clock.instant();

        System.out.println(millis); //1605796928417
        System.out.println(instant);//2020-11-19T14:42:08.417Z

        Date date = Date.from(instant);
        System.out.println(date); //Thu Nov 19 22:43:28 CST 2020

        System.out.println(ZoneId.getAvailableZoneIds());
        //[Asia/Aden, America/Cuiaba,....
        ZoneId zoneId = ZoneId.of("Asia/Aden");
        System.out.println(zoneId);
        System.out.println(zoneId.getRules());

        LocalTime now = LocalTime.now(zoneId);
        System.out.println(now);

//        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)
//                .withLocale(Locale.CHINA);
//        LocalTime localTime = LocalTime.parse("13:37", dateTimeFormatter);
//        System.out.println(localTime);

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss");
        System.out.println(formatter.format(LocalDateTime.now()));//2020-11-20 09:10:40

        LocalDate today = LocalDate.now();
        System.out.println(today);
        LocalDate tomorrow = today.plus(1, ChronoUnit.DAYS);
        LocalDate yesterday = tomorrow.minus(2, ChronoUnit.DAYS);
        LocalDate independencecyDay = LocalDate.of(2019, Month.MARCH, 12);
        DayOfWeek dayOfWeek = independencecyDay.getDayOfWeek();*/

        //从字符串解析日期和时间
        String s1 = "2020=11=20 09时17分17秒";
        DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy=MM=dd HH时mm分ss秒");
        LocalDateTime dt1 = LocalDateTime.parse(s1, formatter1);
        System.out.println(dt1); //2020-11-20T09:17:17


        LocalDateTime localDateTime = LocalDateTime.of(LocalDate.now(), LocalTime.now());
        //时间点对象Instant 可以转为老式的j.u.Date对象
        Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
        Date date = Date.from(instant);
        System.out.println(date);
    }
}
